// 
// File:   prism_actions.h
// Author: cionescu
//
// Created on 10 January 2007, 14:58
//

#ifndef _prism_actions_H
#define	_prism_actions_H
#include "prism_tokens.h"
#include "prism_ast.h"

using namespace std;

/*struct token {
    static const int OP_TYPE = 0;
    static const int ID_TYPE = 1;
    static const int CT_TYPE = 2;
    static const int KW_TYPE = 3;
    
    int m_type;
    string m_string;
    
    token(int t, string s):m_type(t), m_string(s) {}
};*/
    
struct scanner_data {
    typedef vector<token*>       stream_t;
    typedef vector<token*>::const_iterator stream_iterator_t;
    typedef map<string, token*>  sym_tab_t;
    stream_t                m_token_stream;
    sym_tab_t               m_symbol_table;
    prism_ast_program       m_ast;
    
    scanner_data() 
        : m_token_stream(),
        m_symbol_table() {}
        
        vector<token*> get_stream() {return m_token_stream;};
};

template <typename DataT, typename TokenTypeT>
struct keyword_action {
    DataT& m_data;
    
    keyword_action(DataT& t):m_data(t) {}
    
    template <typename Iterator>
    void operator()(Iterator const& first, Iterator const& last) const{
        Iterator it(first);
        string s="";
        while (it!=last) {
            s+=*it++;
        }
        cout << s <<endl;
        
        token* t;
        if (m_data.m_symbol_table.find(s)==m_data.m_symbol_table.end()) {
            t = new TokenTypeT(s);
            m_data.m_symbol_table[s]=t;
        } else {
            t = m_data.m_symbol_table[s];
        }
        m_data.m_token_stream.push_back(t);
    }
};


#endif	/* _prism_actions_H */

